import request from '@/config/axios'
import { IRoleListData, IRolePageParams, IPostRole, IRoleResource, IRoleAdd } from './types'
const base_url = '/api/role'

/**
 * 分页列角色
 */
export const getRolePage = (params: IRolePageParams):Promise<IResponse<IRoleListData>> => {
  return request.get({ url: `${base_url}/page`, params })
}

/**
 * 添加自定义角色
 */
export const postRole = (data: IPostRole):Promise<IResponse> => {
  return request.post({ url: `${base_url}`, data })
}

/**
 * 编辑角色
 */
export const putRole = (data:IPostRole):Promise<IResponse> => {
  return request.put({ url: `${base_url}`, data })
}

/**
 * 删除自定义角色
 */
export const delRole = (id: number): Promise<IResponse> => {
  return request.delete({ url: `${base_url}/${id}` })
}

/**
 * 列角色对应权限资源
 */
export const getRoleResource = (params: IRoleResource): Promise<IResponse> => {
  return request.get({ url: '/api/role-resource', params })
}

/**
 * 添加角色权限资源
 */
export const postRoleResource = (data:IRoleAdd): Promise<IResponse> => {
  return request.post({ url: '/api/role-resource', data })
}